home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / hips / sources / vfft / inrealft.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-01  |  4.9 KB  |  191 lines

  1. /*
  2. %    INREALFT . C
  3. %
  4. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  5.  
  6. This software is copyright (C) by the Lawrence Berkeley Laboratory.
  7. Permission is granted to reproduce this software for non-commercial
  8. purposes provided that this notice is left intact.
  9.  
  10. It is acknowledged that the U.S. Government has rights to this software
  11. under Contract DE-AC03-765F00098 between the U.S.  Department of Energy
  12. and the University of California.
  13.  
  14. This software is provided as a professional and academic contribution
  15. for joint exchange. Thus, it is experimental, and is provided ``as is'',
  16. with no warranties of any kind whatsoever, no support, no promise of
  17. updates, or printed documentation. By using this software, you
  18. acknowledge that the Lawrence Berkeley Laboratory and Regents of the
  19. University of California shall have no liability with respect to the
  20. infringement of other copyrights by any part of this software.
  21.  
  22. For further information about this notice, contact William Johnston,
  23. Bld. 50B, Rm. 2239, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
  24. (wejohnston@lbl.gov)
  25.  
  26. For further information about this software, contact:
  27.     Jin Guojun
  28.     Bld. 50B, Rm. 2275, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
  29.     g_jin@lbl.gov
  30.  
  31. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  32. %
  33. % AUTHOR    Guojun Jin - LBL    12/30/90
  34. */
  35.  
  36. #include "complex.h"
  37. #include "header.def"
  38. #include "imagedef.h"
  39.  
  40. U_IMAGE    uimg;
  41.  
  42. bool    dimens;
  43. char    usage[]="options\n\
  44.     -B    BYTE formated output\n\
  45.     [<] VFFT [> image]\n";
  46. VType    *otemp;
  47. MType    fsize;
  48. int    Omin, Omax=255;
  49.  
  50. #define    cln    uimg.width
  51. #define    row    uimg.height
  52. #define    frm    uimg.frames
  53.  
  54.  
  55. main (argc,argv)
  56. int    argc;
  57. char**    argv;
  58. {
  59. bool    bflag=0;
  60. int    dimen1len, dimen2size, f, i;
  61.  
  62. format_init(&uimg, IMAGE_INIT_TYPE, HIPS, -1, *argv, "S20-1");
  63. uimg.o_form=IFMT_FLOAT;
  64.  
  65. for (i=1; i<argc; i++)
  66.     if (*argv[i] == '-')    {
  67.     int    k=1;
  68.     switch (argv[i][k++])    {
  69.     case 'D':
  70.         dimens = argv[i][k] == '2';
  71.         break;
  72.     case 'B':
  73.         bflag++;    break;
  74.     case 'O':
  75.         if (i+1 >= argc)    break;
  76.         if (strcmp(argv[i]+k, "max")==0)
  77.             Omax = atoi(argv[++i]);
  78.         else if (strcmp(argv[i]+k, "min")==0)
  79.             Omin = atoi(argv[++i]);
  80.         break;
  81. #ifdef    IBMPC
  82.     case 'i':if (avset(argc, argv, &i, &k, 1) &&
  83.             freopen(argv[i]+k, "rb", stdin))    break;
  84.         message("can't open %s as image input", argv[i]);
  85.         goto    errout;
  86. #endif
  87.     case 'o':if (avset(argc, argv, &i, &k, 1) &&
  88.             freopen(argv[i]+k, "wb", stdout))    break;
  89.         message("%s can't be opened", argv[i]);
  90.     default:
  91. errout:        usage_n_options(usage, i, argv[i]);
  92.     }
  93.     }
  94.     else if ((in_fp=freopen(argv[i], "r", stdin) == NULL))
  95.     syserr("can't open frame file - %s", argv[i]);
  96.  
  97. io_test(fileno(in_fp), goto    errout);
  98.  
  99. (*uimg.header_handle)(HEADER_READ, &uimg, 0, 0);
  100. fsize = row * cln;
  101. dimen1len = (cln>>1) + 1;
  102. dimen2size = dimen1len * row << 1;
  103. dimens = (uimg.in_form==IFMT_DVFFT2D || uimg.in_form==IFMT_VFFT2D);
  104.  
  105. work_space_init(MAX(MAX(cln, row), frm));
  106.  
  107. if (uimg.in_form == IFMT_DVFFT2D || uimg.in_form == IFMT_DVFFT3D)    {
  108. double    *ibuf = nzalloc(fsize, sizeof(*ibuf), "fibuf"),
  109.     *obuf = nzalloc(dimen2size*(dimens?1:frm), sizeof(*obuf), "fobuf");
  110.  
  111.     uimg.o_form = IFMT_FLOAT;
  112.     uimg.pxl_out = sizeof(float);
  113. }
  114. else    {
  115. float    *obuf = nzalloc(fsize, sizeof(*obuf), "fobuf"),
  116.     *ibuf = nzalloc(dimen2size*(dimens?1:frm), sizeof(*ibuf), "fibuf");
  117.  
  118.     if (bflag)    {
  119.         uimg.o_form = IFMT_BYTE;
  120.         uimg.pxl_out = 1;
  121.         otemp = nzalloc(fsize, 1, "otemp");
  122.     }
  123.     else{    uimg.o_form = IFMT_FLOAT;
  124.         uimg.pxl_out = sizeof(float);
  125.         otemp = obuf;
  126.     }
  127.     (*uimg.header_handle)(HEADER_WRITE, &uimg, argc, argv, True);
  128.  
  129.     if (!dimens && frm>1)    {
  130.     int    r;
  131.     register COMPLEX    *cmptr, *cp;
  132.     register int    c, n=frm, dimen1size = dimen1len;
  133.  
  134.         fsize = frm*dimen2size;
  135.         i = fread(ibuf, sizeof(*ibuf), fsize, in_fp);
  136.         if (i != fsize)
  137.             syserr("3d[%ld] read %d", fsize, i);
  138.  
  139.         load_w(frm);
  140.  
  141.         for (r=0; r<row; r++)
  142.             for (c=0; c<dimen1size; c++){
  143.             cp = (COMPLEX*)ibuf + r*dimen1size + c;
  144.             cmptr = cmpx_in;
  145.             for (i = 0; i < n; i++, cp+=dimen2size>>1) {
  146.                 c_re (cmptr [i]) = c_re(*cp);
  147.                 c_im (cmptr [i]) = -c_im(*cp);
  148.             }
  149.  
  150.             Fourier(cmptr, n, cmpx_out);
  151.  
  152.             cp = (COMPLEX*)ibuf + r*dimen1size + c;/* store back to src */
  153.             cmptr = cmpx_out;
  154.             for (i = 0; i < n; i++, cp+=dimen2size>>1)
  155.                 *cp = cmptr[i];
  156.             }
  157.     }
  158.  
  159.     fsize = row * cln;
  160.     for (f=0; f<frm; f++)    {
  161.         if (dimens)    {
  162.         i = fread(ibuf, sizeof(*ibuf), dimen2size, in_fp);
  163.         if (i != dimen2size)    syserr("2d[%d] read %d", dimen2size,i);
  164.         }
  165.  
  166.         vrft2d(ibuf + (dimens?0:f*dimen2size), cln, row, obuf);
  167.         if (uimg.o_form != IFMT_FLOAT)    {
  168.         ftob(obuf, otemp, fsize, 1./(fsize*(uimg.in_form&1 ? frm:1)));
  169.         }
  170.         i = fwrite(otemp, uimg.pxl_out, fsize, out_fp);
  171.         if (i != fsize)    syserr("3d write[%d] %d", fsize, i);
  172.     }
  173. }
  174. }
  175.  
  176.  
  177. ftob(ibp, obp, n, scale)
  178. register float*    ibp;
  179. register byte    *obp;
  180. register MType    n;
  181. register float    scale;
  182. {
  183. register int    i;
  184.  
  185. #ifdef    _DEBUG_
  186. message("%d FtoB\n", n);
  187. #endif
  188. for (i=0; i<n; i++)
  189.     *obp++ = *ibp++ * scale;
  190. }
  191.